import {
    getDioceseHomeAll
} from '../../../api/diocese';
let diocese_circle = [];
let diocese_text = [];
export const dioceseMarker = async (map, province_adcode, callback) => {
    map.remove(map.getAllOverlays('marker'));
    map.remove(map.getAllOverlays('circle'));
    map.clearInfoWindow();
    if(diocese_circle.length>0){
        map.remove(diocese_circle);
        diocese_circle=[];
    }
    if(diocese_text.length>0){
        map.remove(diocese_text);
        diocese_text=[];
    }
    let response = await getDioceseHomeAll({
        province_adcode
    });
    let list = response.data.data;
    if (response.status != 200 || !list) return;
    for (let item of list) {
        const lnglat = [item.cathedral.lng, item.cathedral.lat]
        let circle = new AMap.CircleMarker({
            center: lnglat,
            radius: 40, //3D视图下，CircleMarker半径不要超过64px
            strokeColor: 'rgba(0,0,255,1)',
            strokeWeight: 0,
            strokeOpacity: 0,
            fillColor: 'rgba(0,0,255,1)',
            fillOpacity: 0.6,
            bubble: true,
            cursor: 'pointer',
        })
        let text = new AMap.Text({
            position: lnglat,
            anchor: 'center',
            text: `${item.title}<br/>${item.parish_num}`,
            bubble: true,
            zIndex: -10,
            style: {
                'font-size': '14px',
                'color': 'rgba(255, 255, 255, 1)',
                'background-color': 'rgba(0, 0, 0, 0)',
                'border': '0px',
                'text-align': 'center'
            },
        });
        circle.on('click', (event) => {
            map.remove(diocese_circle);
            map.remove(diocese_text);
            callback(event, item)
        })
        text.on('click', (event) => {
            map.remove(diocese_circle);
            map.remove(diocese_text);
            callback(event, item)
        })
        // map.add(circle);
        // map.add(text);
        diocese_circle.push(circle);
        diocese_text.push(text);
    }
    map.add(diocese_text);
    map.add(diocese_circle);
}
